/***************************************************************************

-------------------
    begin                : 
    copyright            : kuzkok
    email                : kuzkok at gmail.com

***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*   
*   Данная программа является свободным программным обеспечением;         *
*   Вы можете распространять ее и/или модифицировать в соответствии с     *
*   GNU General Public License опубликованной Фондом свободного           *
*   программного обеспечения; используемая версия лицензии - 2 или        *
*   (по вашему выбору) любая более поздняя                                *
***************************************************************************/

#include "controlpoint.h"

ControlPoint::ControlPoint() :
        CenterlinePoint("controlpoint")
{
}

ControlPoint::ControlPoint(QUuid theEventID) :
        CenterlinePoint(theEventID, "controlpoint")
{
    if(mObjectState)
    {
        mStationValue = mSelectQuery->value(mSelectQuery->record().indexOf("stationvalue")).toDouble();
        mControlPointAngle = mSelectQuery->value(mSelectQuery->record().indexOf("controlpointangle")).toDouble();
        mControlPointType = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("controlpointtype")).toString());
        mPIDDirection = mSelectQuery->value(mSelectQuery->record().indexOf("piddirection")).toString();
        mSubTypeCD = mSelectQuery->value(mSelectQuery->record().indexOf("subtypecd")).toInt();
    }
}

void ControlPoint::buildInsertStatement()
{
    CenterlinePoint::buildInsertStatement();
    mInsertStatementFields += ", stationvalue"
                             ", controlpointangle"
                             ", controlpointtype"
                             ", piddirection"
                             ", subtypecd";
    mInsertStatementValues += ", :stationvalue"
                             ", :controlpointangle"
                             ", :controlpointtype"
                             ", :piddirection"
                             ", :subtypecd";
}

void ControlPoint::buildUpdateStatement()
{
    CenterlinePoint::buildUpdateStatement();
    mUpdateStatement += ",stationvalue = :stationvalue"
                       ",controlpointangle = :controlpointangle"
                       ",controlpointtype = :controlpointtype"
                       ",piddirection = :piddirection"
                       ",subtypecd = :subtypecd";
}

void ControlPoint::bindQueryValues(QSqlQuery &query)
{
    CenterlinePoint::bindQueryValues(query);
    query.bindValue(":stationvalue", mStationValue);
    query.bindValue(":controlpointangle", mControlPointAngle);
    query.bindValue(":controlpointtype", UuidToVariant(mControlPointType));
    query.bindValue(":piddirection", mPIDDirection);
    query.bindValue(":subtypecd", mSubTypeCD);
}
